<template>
	<view class="content">
		<view class="Nav" style="display: flex;align-items: center;background: transparent;opacity: 1;padding: 113rpx 30rpx 35rpx 30rpx;
			left: 0;width: 100%;">
			<u-icon name="arrow-left" size="40rpx" color="#fff" @click="Goback"></u-icon>
			<view style="font-weight: bold;font-size: 36rpx;color: #FFFFFF;margin-left: 244rpx;">
				新零售
			</view>
		</view>
		<view>
			<view class="list_box">
				<view class="list_item" v-for="(item,index) in list" :key="index" @tap="goodsDetail(item.id)">
					<image :src="item.image_url" mode="aspectFill" class="list_img"></image>
					<view class="list_name">
						{{item.name}}
					</view>
					<view class="demo gray_title">
						<view class="list_old_price">
							￥{{item.mktprice}}
						</view>
						已售{{item.buy_count > 99 ? '99+' : item.buy_count}}件
					</view>
					<view class="red_price">￥{{item.price}}</view>
				</view>
				<view v-if="showEnd && list.length > 0" class="endLine">
					-&nbsp;&nbsp;我是有底线的&nbsp;&nbsp;-
				</view>
				<view v-if="list.length === 0" class="noData">
					暂无数据，请检查您的搜索条件！
				</view>
			</view>
		</view>
		<jh-tabbar></jh-tabbar>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				avatar: '',
				nickname: '',
				page: 1,
				pageSize: 20,
				keyword: "",
				list: [],
				isLoading: false,
				showEnd: false,
				timer: null,
				goodspoint: 0
			};
		},
		onLoad() {
			this.GetList();
		},
		onShow() {
			this.getUserInfo()
		},
		methods: {
			Goback() {
				uni.navigateBack()
			},
			goodsDetail: function(id) {
				let url = '/pages/goods/index/index?id=' + id;
				this.$common.navigateTo(url);
			},
			getUserInfo() {
				this.$api.userInfo({}, res => {
					this.avatar = res.data.avatar;
					this.nickname = res.data.nickname;
					this.goodspoint = res.data.goodspoint
				})
			},
			//搜索
			Search() {
				if (this.timer) { // 如果已经设置了定时器，就清除已有的定时器
					clearTimeout(this.timer);
				}
				this.timer = setTimeout(() => {
					this.page = 1;
					this.showEnd = false;
					this.GetList();
				}, 1000); // 设置新的定时器，500ms 后执行搜索
			},
			//获取数据
			GetList() {
				if (this.isLoading || this.showEnd) {
					return;
				}
				this.isLoading = true;
				this.$api.goodsList({
					page: this.page,
					where: `{\"goods_type\":\"2\"}`,
					limit: this.pageSize,
					keyword: this.keyword,
				}, res => {
					if (res.status) {
						if (this.page >= res.data.total_page) {
							// 没有数据了
							this.loadStatus = 'noMore'
						} else {
							// 未加载完毕
							this.loadStatus = 'more'
							this.page++
						}
						this.list = [...this.list, ...res.data.list]
					} else {
						this.$common.errorToShow(res.msg)
					}
				});
			},
			//跳转
			GoDetail(ID, PointID) {
				uni.navigateTo({
					url: '/pages/point/detail?id=' + ID + '&pid=' + PointID
				})
			}
		},
		onReachBottom() {
			this.GetList();
		},
	};
</script>

<style lang="scss" scoped>
	.red_price {
		font-weight: bold;
		font-size: 36rpx;
		color: #FF363A;
		line-height: 35rpx;
	}
	.gray_title {
		font-size: 20rpx;
		color: #999999;
		line-height: 34rpx;
		margin-top: 15rpx;
		margin-bottom: 23rpx;
	}

	.list_name {
		font-size: 28rpx;
		color: #FFFFFF;
		line-height: 34rpx;
		overflow: hidden;
		text-overflow: ellipsis;
		display: -webkit-box;
		-webkit-box-orient: vertical;
		-webkit-line-clamp: 1;
	}

	.list_img {
		width: 302rpx;
		height: 302rpx;
		border-radius: 10rpx;
		margin-bottom: 11rpx;
	}

	.list_item {
		width: 338rpx;
		background: #232429;
		box-shadow: 0rpx 5rpx 40rpx 1rpx rgba(255, 255, 255, 0.45);
		border-radius: 10rpx;
		padding: 17rpx 18rpx 43rpx;
		margin-bottom: 20rpx;
	}

	.list_box {
		display: flex;
		justify-content: space-between;
		flex-wrap: wrap;
		padding: 0 30rpx 110rpx;
	}

	.goods-head {
		display: flex;
		height: 200rpx;
		color: #fff;

		.goods-conten {
			font-size: 40rpx;
			font-weight: 800;
			padding-top: 40rpx;
			margin-left: 40rpx;

			view {
				text-align: left;
				margin-top: 10rpx;

			}
		}
	}

	.Search {
		margin: 30rpx 30rpx 50rpx;
		color: #fff;
		font-size: 70rpx;
	}

	.GoodsList {
		margin: 0 30rpx;

		.GoodsItem {
			display: flex;
			background: #202126;
			padding: 15rpx;
			margin-bottom: 30rpx;
			border-radius: 20rpx;


			.ItemLeft {
				margin-right: 26rpx;
			}

			.ItemRight {
				padding-top: 15rpx;

				.Name {
					height: 90rpx;
					color: #FFFFFF;
					font-weight: 800;
					display: -webkit-box;
					overflow: hidden;
					-webkit-line-clamp: 2;
					-webkit-box-orient: vertical;
				}

				.DelPrice_BuyNum {
					display: flex;
					justify-content: space-between;
					font-size: 24rpx;
					color: #B9B9B9;
					margin: 25rpx 0 20rpx;

					.DelPrice {
						text-decoration: line-through;
					}

					.BuyNum {}
				}

				.BuyPrice {
					font-size: 28rpx;
					color: #F2D7AA;

					text {
						font-weight: bold;
						font-size: 36rpx;
					}
				}

				.Btn {
					display: inline-block;
					margin-left: 200rpx;
					margin-top: 40rpx;
					padding: 10rpx 55rpx;
					background: #e8c998;
					border-radius: 10rpx;
				}
			}
		}
	}

	.endLine {
		text-align: center;
		margin-bottom: 20rpx;
		color: #999;
	}

	.noData {
		text-align: center;
		margin-top: 100rpx;
		color: #999;
	}
</style>